package com.yn.scinsp.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yn.common.base.BaseController;
import com.yn.core.toolbox.ajax.AjaxResult;
import com.yn.core.toolbox.kit.JsonKit;
import com.yn.scinsp.model.InspLineLoc;
import com.yn.scinsp.service.InspLineLocService;

/**
 * Generated by.
 * 2017-05-18 23:27:46
 */
@Controller
@RequestMapping("/inspLineLoc")
public class InspLineLocController extends BaseController {
	private static String CODE = "inspLineLoc";
	private static String PREFIX = "scinsp_lineloc";
	private static String LIST_SOURCE = "inspLineLoc.list";
	private static String BASE_PATH = "/scinsp/inspLineLoc/";
	
	@Autowired
	InspLineLocService service;
	
	@RequestMapping(KEY_MAIN)
	public String index(ModelMap mm) {
		mm.put("code", CODE);
		return BASE_PATH + "inspLineLoc.html";
	}

	@RequestMapping(KEY_ADD)
	public String add(ModelMap mm) {
		mm.put("code", CODE);
		return BASE_PATH + "inspLineLoc_add.html";
	}

	@RequestMapping(KEY_EDIT + "/{id}")
	public String edit(@PathVariable Integer id, ModelMap mm) {
		InspLineLoc inspLineLoc = service.findById(id);
		mm.put("model", JsonKit.toJson(inspLineLoc));
		mm.put("id", id);
		mm.put("code", CODE);
		return BASE_PATH + "inspLineLoc_edit.html";
	}

	@RequestMapping(KEY_VIEW + "/{id}")
	public String view(@PathVariable Integer id, ModelMap mm) {
		InspLineLoc inspLineLoc = service.findById(id);
		mm.put("model", JsonKit.toJson(inspLineLoc));
		mm.put("id", id);
		mm.put("code", CODE);
		return BASE_PATH + "inspLineLoc_view.html";
	}

	@ResponseBody
	@RequestMapping(KEY_LIST)
	public Object list() {
		Object grid = paginate(LIST_SOURCE);
		return grid;
	}

	@ResponseBody
	@RequestMapping(KEY_SAVE)
	public AjaxResult save() {
		InspLineLoc inspLineLoc = mapping(PREFIX, InspLineLoc.class);
		boolean temp = service.save(inspLineLoc);
		if (temp) {
			return success(SAVE_SUCCESS_MSG);
		} else {
			return error(SAVE_FAIL_MSG);
		}
	}

	@ResponseBody
	@RequestMapping(KEY_UPDATE)
	public AjaxResult update() {
		InspLineLoc inspLineLoc = mapping(PREFIX, InspLineLoc.class);
		boolean temp = service.update(inspLineLoc);
		if (temp) {
			return success(UPDATE_SUCCESS_MSG);
		} else {
			return error(UPDATE_FAIL_MSG);
		}
	}

	@ResponseBody
	@RequestMapping(KEY_REMOVE)
	public AjaxResult remove(@RequestParam String ids) {
		int cnt = service.deleteByIds(ids);
		if (cnt > 0) {
			return success(DEL_SUCCESS_MSG);
		} else {
			return error(DEL_FAIL_MSG);
		}
	}
}
